package git.etl;

import java.sql.Connection;
import javax.sql.DataSource;
import javax.naming.InitialContext;
import javax.naming.Context;

public class Dao
{
	private static DataSource m_dataSource;
	
	public static synchronized Connection getCogdbConnection()
		throws Exception
	{
		if (null == m_dataSource)
		{
			Context ctx = new InitialContext();
			m_dataSource = (DataSource)ctx.lookup("java:comp/env/jdbc/COGDB");
		}
		
		return m_dataSource.getConnection();
		
		/*/Class.forName("oracle.jdbc.driver.OracleDriver");
		return java.sql.DriverManager.getConnection(
				"jdbc:oracle:thin:@172.17.22.47:1521:cogdb", "cognos", "cognos"); */
	}

	public static Connection getConnectionByDataSourceName(String dsName)
		throws Exception
	{
		Context ctx = new InitialContext();
		DataSource ds = (DataSource)ctx.lookup(dsName);
		return ds.getConnection();
	}
}
